//
//  ToolView.swift
//  QizAISwiftDemo
//
//  Created by Mephisto on 2025/4/23.
//

import QMUIKit
import UIKit

class ToolView: UIView {

    override init(frame: CGRect) {
        super.init(frame: frame)
        self.createSubViews()
    }

    @available(*, unavailable)
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    private func createSubViews() {
        self.addSubview(self.hStack)
        self.hStack.addArrangedSubview(self.accountNoTF)
        self.hStack.addArrangedSubview(self.sureBtn)
        self.hStack.addArrangedSubview(self.expandLabelL)
        self.hStack.addArrangedSubview(self.expandSwitch)

        self.setupLayout()
    }

    private func setupLayout() {
        self.hStack.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }

        self.accountNoTF.snp.makeConstraints { make in
            make.height.equalTo(40)
            make.width.equalTo(180)
        }

        self.sureBtn.snp.makeConstraints { make in
            make.height.equalTo(40)
            make.width.equalTo(60)
        }

        self.expandLabelL.snp.makeConstraints { make in
            make.width.equalTo(60)
        }
    }

    // MARK: 懒加载
    private lazy var hStack: UIStackView = {
        let stackV = UIStackView()
        stackV.axis = NSLayoutConstraint.Axis.horizontal
        stackV.isLayoutMarginsRelativeArrangement = true
        stackV.alignment = .center
        stackV.directionalLayoutMargins = .init(
            top: 0, leading: 10, bottom: 0, trailing: 10)
        stackV.spacing = 8
        stackV.insetsLayoutMarginsFromSafeArea = false
        return stackV
    }()

    lazy var accountNoTF: QMUITextField = {
        let textField = QMUITextField()
        textField.textInsets = UIEdgeInsets.init(
            top: 0, left: 10, bottom: 0, right: 10)
        textField.textColor = UIColor.black
        textField.font = .systemFont(ofSize: 12)
        textField.placeholder = "请输入AccountNo eg:PDCxxxxxx"
        textField.clearButtonMode = .always
        textField.autocapitalizationType = .none
        textField.backgroundColor = .white
        return textField
    }()

    lazy var sureBtn: UIButton = {
        let btn = UIButton()
        btn.titleLabel?.font = .systemFont(ofSize: 12)
        btn.setTitle("确定", for: .normal)
        btn.setTitleColor(.white, for: .normal)
        btn.layer.cornerRadius = 8
        btn.layer.masksToBounds = true
        btn.backgroundColor = .blue
        return btn
    }()

    private lazy var expandLabelL: UILabel = {
        let label = UILabel()
        label.font = .systemFont(ofSize: 12)
        label.numberOfLines = 0
        label.qmui_lineHeight = 22
        label.textColor = UIColor.black
        label.text = "展开/收起"
        return label
    }()

    lazy var expandSwitch: UISwitch = {
        let view = UISwitch()
        view.isOn = true
        return view
    }()

}
